﻿//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：FacnType
// *描述：FacnType
// *?2024 HDMCode . All rights reserved.
//* ======================================================================
using System.Collections.Generic;
using UnityEngine;

namespace HDMCode.UIFrame
{
    public abstract class IUIDisplayLife<T> : IUIDisplayLife where T : IUIFrameComponent,new()
    {
        /// <summary>
        /// UI首次加载时执行
        /// </summary>
        /// <param name="value">自定义参数</param>
        /// <param name="entity">当前UI对象</param>
        /// <param name="component">当前UI的组件信息</param>
        public virtual void OnLoadUI<K>(K value,IUIEntity entity, T component) { }
        
        /// <summary>
        /// UI首次加载时执行
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        /// <param name="component">当前UI的组件信息</param>
        public virtual void OnLoadUI(IUIEntity entity, T component) { }
        
        /// <summary>
        /// UI显示时执行
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        /// <param name="component">当前UI的组件信息</param>
        public virtual void OnDisplay(IUIEntity entity, T component) { }
        
        /// <summary>
        /// UI的传参显示时执行
        /// </summary>
        /// <param name="value">传递的参数</param>
        /// <param name="entity">当前UI对象</param>
        /// <param name="component">当前UI的组件信息</param>
        /// <typeparam name="K">传递的类型</typeparam>
        public virtual void OnDisplay<K>(K value, IUIEntity entity, T component){}
        
        /// <summary>
        /// UI销毁时执行
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        /// <param name="component">当前UI组件</param>
        /// <param name="release">执行销毁方式</param>
        public virtual void OnDestroyUI(IUIEntity entity,T component, UIEntityRelease release){release.Remove();}

        /// <summary>
        /// UI克隆时执行
        /// Clone 仅允许通知类型UI使用，且行为由父对象统一管理且仅提供组件参数。
        /// </summary>
        /// <param name="value">需要克隆的参数</param>
        /// <param name="clone">克隆对象</param>
        /// <param name="component">当前克隆的组件</param>
        /// <typeparam name="K">当前参数类型</typeparam>
        public virtual void OnCloneUI<K>(K value,GameObject clone,T component){}

        /// <summary>
        /// 实现基类UI首次加载回调并密封处理类型转换
        /// </summary>
        /// <param name="value">自定义参数</param>
        /// <param name="entity">当前UI对象</param>
        public override sealed void OnLoadUI<K>(K value,UIEntity entity)=>OnLoadUI(value,entity,(T)entity.UIFrameComponent);
        
        /// <summary>
        /// 实现基类UI首次加载回调并密封处理类型转换
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        public override sealed void OnLoadUI(UIEntity entity)=>OnLoadUI(entity,(T)entity.UIFrameComponent);
        
        /// <summary>
        /// 实现基类显示UI回调并密封处理类型转换
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        public override sealed void OnDisplay(UIEntity entity)=>OnDisplay(entity,(T)entity.UIFrameComponent);
        
        /// <summary>
        /// 实现基类传参显示UI回调并密封处理类型转换
        /// </summary>
        /// <param name="value">传递的参数</param>
        /// <param name="entity">当前UI对象</param>
        /// <typeparam name="K">传递的类型</typeparam>
        public override sealed void OnDisplay<K>(K value,UIEntity entity)=>OnDisplay(value,entity,(T)entity.UIFrameComponent);
        
        /// <summary>
        /// 实现基类销毁UI回调并密封处理类型转换
        /// </summary>
        /// <param name="entity">当前UI对象</param>
        /// <param name="release">执行销毁方式</param>
        public override sealed void OnDestroyUI(UIEntity entity,UIEntityRelease release)=> OnDestroyUI(entity,(T)entity.UIFrameComponent,release);

        /// <summary>
        /// 克隆时执行
        /// </summary>
        /// <param name="value">传递的参数</param>
        /// <param name="components">当前UI拥有的组件</param>
        /// <typeparam name="K">当前参数类型</typeparam>
        public override sealed void OnClone<K>(K value,GameObject clone,List<UIComponentElement> components)
        {
            T com = new T();
            com.SetComponents(components);
            OnCloneUI(value,clone,com);
        }
        
    }
}
